home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /***************************************************************************
- /* bookmove.c
- /* this file contains routines to open and turn the pages of the demobook
- /*
- /* need to:
- /* 1) add cool binding to book
- /* 2) pre-calculate lighting arrays
- /* 3) integrate frame-by-frame rotation
- /* 4) use color-map ramps on LIGHT (starter) graphics instead of
- /* switching back and forth between single and double buffer
- /*
- /* David Ligon
- ****************************************************************************/
-
- #include <math.h>
- #include <stdio.h>
- #include <gl.h>
- #include <get.h>
- #include "exglobals.h"
- #include "bookmove.h"
- #include "bookgfx.h"
- #include "exbookglo.h"
-
- #define DBUG FALSE
- #define LIGHTCALC FALSE
- #define DRAWSOLIDPAGES FALSE
-
- void mknorms();
- static float getangle(register float vtx1[3], register float vtx2[3]);
- void mkangles(void);
- void dographics(float vtx[3], float angle);
- void drawicons(struct pagestruct *thispage, int side, float position[PGSEGS][VPGSEGS][3], float rot_angle[PGSEGS-1]);
-
- float ropenangle[OPENFRAMES][PGSEGS -1];
- float lopenangle[OPENFRAMES][PGSEGS -1];
- float backrturnangle[TURNFRAMES][PGSEGS -1];
- float frontrturnangle[TURNFRAMES][PGSEGS -1];
- float backlturnangle[TURNFRAMES][PGSEGS -1];
- float frontlturnangle[TURNFRAMES][PGSEGS -1];
-
-
- void mk_open_arrays(void);
- void mk_turn_arrays(void);
- void openbook(register int rotateflag);
- void drawopenframe(register int pgn);
- void pickdrawopenframe(register int pgn);
- void turnpage(int side);
- void rtol_turn(void);
- void ltor_turn(void);
- void mksinglebuffer(void);
- void mkdoublebuffer(void);
- int isdoublebuffer(void);
- void drawbinding(void);
-
- void pickdrawedges(register float ropg[PGSEGS][VPGSEGS][THREED],
- register float lopg[PGSEGS][VPGSEGS][THREED],
- register float robase[3][2][THREED], register float lobase[3][2][THREED]);
- static void drawopencover(float rcover[COVERSEGS][2][THREED],
- float lcover[PGSEGS][2][THREED]);
- static void fillopenpages(float ropg[PGSEGS][VPGSEGS][THREED],
- float lopg[PGSEGS][VPGSEGS][THREED], float robase[3][2][THREED],
- float lobase[3][2][THREED]);
- static void drawopenpages(float rpg[PGSEGS][VPGSEGS][THREED],
- float lpg[PGSEGS][VPGSEGS][THREED]);
- static void drawsquare(float pgarray[PGSEGS][VPGSEGS][THREED], int x, int y);
- static void drawoutlinesquare(float pgarray[PGSEGS][VPGSEGS][THREED], int x, int y);
- void setcovercolor(struct grptmpltstruct *grpptr);
- static void mkcolor(float carray[3], float srcarray[3], float coord[3]);
- static void drawcrack();
- static void mk_right_basepg(void);
-
- #if DRAWSOLIDPAGES
- static void drawsolidpages(void);
- #endif
-
- #if LIGHTCALC
- static void printcolor(float carray[3]);
- #endif
-
-
- /*******************************************************
- /* BUFFER STUFF
- /******************************************************/
-
- /* return TRUE is drawmode is double buffer */
- int isdoublebuffer()
- {
- register int isdouble;
-
- isdouble = getdisplaymode();
-
- if (isdouble == DMDOUBLE || isdouble == DMRGBDOUBLE)
- return(TRUE);
- else
- return(FALSE);
- }
-
-
- /* return TRUE if is eight bitplane machine */
- int iseightbit()
- {
- if (getgdesc(GD_BITS_NORM_SNG_RED) +
- getgdesc(GD_BITS_NORM_SNG_GREEN) +
- getgdesc(GD_BITS_NORM_SNG_BLUE) == 8) {
- return(TRUE);
- } else {
- return(FALSE);
- }
- }
-
-
- /* clear back buffer and make single buffer for static page */
- void mksinglebuffer()
- {
- if (isdoublebuffer() && iseightbit()) {
- /* clear back buffer so old image won't show */
- /* frontbuffer(TRUE); */
- cpack(0);
- clear();
- singlebuffer();
- /* gconfig(); */
- }
- }
-
-
- /* make doublebuffer for movement */
- void mkdoublebuffer()
- {
- if (!isdoublebuffer() && iseightbit()) {
- /* either get funky colors or blank screen-funky colors look better */
- cpack(0);
- clear();
- doublebuffer();
- /* gconfig(); */
- }
- }
-
-
- /*******************************************************
- /* ICON STUFF
- /******************************************************/
-
- void unhighlighticon()
- {
- dooverlayview();
- color(PUP_CLEAR);
- clear();
- }
-
- void highlightsquare(int sideflag, register int x, register int y)
- {
- if (x >= 0 && y >= 0)
- {
- unhighlighticon();
- color(PUP_COLOR);
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- if (sideflag == 0) /* leftside */
- drawoutlinesquare(lopenpg[0], x, y);
- else /* right side */
- drawoutlinesquare(ropenpg[0], x, y);
- popmatrix();
- dobookview();
- }
- }
-
- void highlighticon(pk, thispage, side)
- int pk;
- struct pagestruct *thispage;
- int side;
- {
- int j, k, limit;
- struct polylist *curpoly;
- float angle;
- struct icntmpltstruct *curicon;
- struct iconstruct *tmpiconptr;
- int i, numicons;
-
- if (side == 0)
- {
- tmpiconptr = thispage -> backicons;
- numicons = thispage->backnumicons;
- if (numicons > 21)
- numicons = 20;
- }
- else if (side == 1)
- {
- tmpiconptr = thispage ->fronticons;
- numicons = thispage->frontnumicons;
- if (numicons > 21)
- numicons = 20;
- }
- if (tmpiconptr != NULL && pk <= numicons)
- {
- i = 0;
- while (i < pk)
- {
- if (!Hide || tmpiconptr->ok)
- i++;
- tmpiconptr = tmpiconptr->nexticon;
- }
-
- unhighlighticon();
- color(PUP_COLOR);
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- if (side == 1) /* right page */
- drawoutlinesquare(ropenpg[0], (int)(tmpiconptr->xposition_ndx), (int)(tmpiconptr->yposition_ndx));
- else if (side == 0) /* left page */
- drawoutlinesquare(lopenpg[0], (int)(tmpiconptr->xposition_ndx), (int)(tmpiconptr->yposition_ndx));
- popmatrix();
- dobookview();
- }
- }
-
- void pickdrawicons(struct pagestruct *thispage, int side, float position[PGSEGS][VPGSEGS][3], float rot_angle[PGSEGS-1])
- {
- register long cursm;
- register short x, y;
- struct iconstruct *tmpiconptr;
- int i;
-
- if (side == FRONT)
- tmpiconptr = thispage->fronticons;
- else
- tmpiconptr = thispage->backicons;
-
- i = 0;
- while (i < ICONLIMIT && tmpiconptr != NULL)
- {
- if (!Hide || tmpiconptr->ok)
- {
- pushmatrix();
- if (side == BACK)
- loadname(-i-1);
- else
- loadname(i);
- x = tmpiconptr->xposition_ndx;
- y = tmpiconptr->yposition_ndx;
- drawsquare(position, x, y);
- popmatrix();
- i++;
- }
- tmpiconptr = tmpiconptr->nexticon;
- }
- }
-
- void drawicons(struct pagestruct *thispage, int side, float position[PGSEGS][VPGSEGS][3], float rot_angle[PGSEGS-1])
- {
- register long cursm;
- register short x, y;
- struct iconstruct *tmpiconptr;
- int i;
- float transname;
-
- cursm = getsm();
- shademodel(FLAT);
-
- if (side == FRONT)
- tmpiconptr = thispage->fronticons;
- else
- tmpiconptr = thispage->backicons;
-
- i = 0;
- while (i < ICONLIMIT && tmpiconptr != NULL)
- {
- if (!Hide || tmpiconptr->ok)
- {
- transname = -.15;
- pushmatrix();
- x = tmpiconptr->xposition_ndx;
- y = tmpiconptr->yposition_ndx;
- if (i == selected && thispage == selectedpage)
- {
- c3s(morecolors[11]);
- if (side == FRONT)
- drawoutlinesquare(ropenpg[0], x, y);
- else
- drawoutlinesquare(lopenpg[0], x, y);
- }
- if (side == FRONT)
- {
- translate(position[x][y][0], position[x][y][1]+.4, position[x][y][2]);
- rotate( (int)(rot_angle[x] * 10 + 0.5), 'y');
- }
- else
- {
- translate(position[x+1][y][0], position[x+1][y][1]+.4, position[x+1][y][2]);
- rotate( (int)(rot_angle[x] * 10 + 0.5), 'y');
- }
- if (tmpiconptr->iconptr->poly != NULL)
- drawicon_geom(0, tmpiconptr->iconptr);
- else if (tmpiconptr->iconptr->tex_image != NULL)
- drawicon_img(0,tmpiconptr->iconptr);
- else
- transname = 1.125;
- pushmatrix();
- translate(0.0, transname, 0.0);
- draw_demoname(tmpiconptr->iconptr);
- popmatrix();
- popmatrix();
- i++;
- } /* end if tmpiconptr->ok */
- tmpiconptr = tmpiconptr->nexticon;
- }
-
- shademodel(cursm);
- }
-
- void drawselectedicon( struct pagestruct *thispage, int iconnum)
- {
- short x, y;
- struct iconstruct *tmpiconptr;
- int i;
-
- if (thispage != NULL)
- {
- if (thispage == leftpage)
- tmpiconptr = thispage->backicons;
- else if (thispage == rightpage)
- tmpiconptr = thispage->fronticons;
- i = 0;
- while (tmpiconptr != NULL && (i != iconnum || (!tmpiconptr->ok && Hide)))
- {
- if (!Hide || tmpiconptr->ok)
- i++;
- tmpiconptr = tmpiconptr->nexticon;
- }
-
- if (tmpiconptr != NULL)
- {
-
- x = tmpiconptr->xposition_ndx;
- y = tmpiconptr->yposition_ndx;
-
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- frontbuffer(TRUE);
- /*
- if (thispage == leftpage)
- {
- drawsquare(lopenpg[0], x, y);
- pushmatrix();
- translate( lopenpg[0][x][y][0], lopenpg[0][x][y][1]+.4, lopenpg[0][x][y][2]);
- rotate( (int)(lopenangle[0][x] * 10 + 0.5), 'y');
- }
- else if (thispage == rightpage)
- {
- drawsquare(ropenpg[0], x, y);
- pushmatrix();
- translate(ropenpg[0][x][y][0], ropenpg[0][x][y][1]+.4, ropenpg[0][x][y][2]);
- rotate( (int)(ropenangle[0][x] * 10 + 0.5), 'y');
- }
- if (tmpiconptr->iconptr->poly != NULL)
- drawicon_geom(0, tmpiconptr->iconptr);
- else if (tmpiconptr->iconptr->tex_image != NULL)
- drawicon_img(0,tmpiconptr->iconptr);
- pushmatrix();
- translate(0.0, .2, 0.0);
- draw_demoname(tmpiconptr->iconptr);
- popmatrix();
- popmatrix();
- */
- if (thispage == leftpage)
- {
- c3s(morecolors[11]);
- drawoutlinesquare(lopenpg[0], x, y);
- }
- else if (thispage == rightpage)
- {
- c3s(morecolors[11]);
- drawoutlinesquare(ropenpg[0], x, y);
- }
-
- frontbuffer(FALSE);
- popmatrix();
- }
- }
- }
-
- void undrawselectedicon( struct pagestruct *thispage, int iconnum)
- {
- short x, y;
- struct iconstruct *tmpiconptr;
- int i;
- float transname;
-
- if (thispage != NULL)
- {
- if (thispage == leftpage)
- tmpiconptr = thispage->backicons;
- else if (thispage == rightpage)
- tmpiconptr = thispage->fronticons;
- i = 0;
- while (tmpiconptr != NULL && (i != iconnum || (!tmpiconptr->ok && Hide)))
- {
- if (!Hide || tmpiconptr->ok)
- i++;
- tmpiconptr = tmpiconptr->nexticon;
- }
-
- if (tmpiconptr != NULL)
- {
- x = tmpiconptr->xposition_ndx;
- y = tmpiconptr->yposition_ndx;
- transname = -.15;
-
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- frontbuffer(TRUE);
- if (thispage == leftpage)
- {
- drawsquare(lopenpg[0], x, y);
- pushmatrix();
- translate( lopenpg[0][x+1][y][0], lopenpg[0][x+1][y][1]+.4,
- lopenpg[0][x+1][y][2]);
- rotate( (int)(lopenangle[0][x] * 10 + 0.5), 'y');
- }
- else if (thispage == rightpage)
- {
- drawsquare(ropenpg[0], x, y);
- pushmatrix();
- translate(ropenpg[0][x][y][0],ropenpg[0][x][y][1]+.4, ropenpg[0][x][y][2]);
- rotate( (int)(ropenangle[0][x] * 10 + 0.5), 'y');
- }
- if (tmpiconptr->iconptr->poly != NULL)
- drawicon_geom(0, tmpiconptr->iconptr);
- else if (tmpiconptr->iconptr->tex_image != NULL)
- drawicon_img(0,tmpiconptr->iconptr);
- else
- transname = 1.125;
- pushmatrix();
- translate(0.0, transname, 0.0);
- draw_demoname(tmpiconptr->iconptr);
- popmatrix();
- popmatrix();
-
- frontbuffer(FALSE);
- popmatrix();
- }
- }
- }
-
- void dographics(float vtx[3], float angle)
- {
- register int i;
-
- static float sqr[4][3] = {{0.3,0.6,0.0},{1.7,0.6,0.0},{1.7,1.7,0.0},
- {0.3,1.7,0.0}};
- static float tri[3][3] = {{0.6,0.2,0.0},{1.8,0.7,0.0},{1.0,1.2,0.0}};
- float sqcolor[3];
- float tricolor[3];
-
- sqcolor[0] = sqcolor[1] = 0.0; sqcolor[2] = 1.0;
- tricolor[0] = 0.0; tricolor[1] = 0.5; tricolor[2] = 1.0;
-
- pushmatrix();
- translate(vtx[0],vtx[1],vtx[2]);
- rotate((int)(angle * 10 + 0.5),'y');
-
- for (i = 1; i < 6; i++) {
- pushmatrix();
- scale(1.0/(float)i,1.0/(float)i,1.0);
-
- c3f(sqcolor);
- bgnpolygon();
- v3f(sqr[0]);
- v3f(sqr[1]);
- v3f(sqr[2]);
- v3f(sqr[3]);
- endpolygon();
-
- cpack(0);
- bgnclosedline();
- v3f(sqr[0]);
- v3f(sqr[1]);
- v3f(sqr[2]);
- v3f(sqr[3]);
- endclosedline();
- popmatrix();
- }
-
- for(i = 1; i < 6; i++) {
- pushmatrix();
- scale(1.0/(float)i,1.0/(float)i,1.0);
- c3f(tricolor);
- bgnpolygon();
- v3f(tri[0]);
- v3f(tri[1]);
- v3f(tri[2]);
- endpolygon();
-
- cpack(0);
- bgnclosedline();
- v3f(tri[0]);
- v3f(tri[1]);
- v3f(tri[2]);
- endclosedline();
- popmatrix();
- }
- popmatrix();
- }
-
-
- /*******************************************************
- /* INIT STUFF
- /******************************************************/
-
- /* make arrays for opening the book */
- void mk_open_arrays()
- {
- register int pgn, x, y;
-
- /* make the array for the right pages opening the book */
- for (pgn = 0; pgn < OPENFRAMES; pgn++) {
- for (x = 0;x < PGSEGS; x++) {
- for(y = 0; y < VPGSEGS; y++) {
- ropenpg[pgn][x][y][0] = openpg[pgn][x][0] * SCALE;
- ropenpg[pgn][x][y][1] = PGHT/(VPGSEGS - 1) * y;
- ropenpg[pgn][x][y][2] = openpg[pgn][x][1] * SCALE;
- }
- }
- }
-
- /* make the array for the left pages opening the book */
- for (pgn = 0; pgn < OPENFRAMES; pgn++) {
- for (x = 0;x < PGSEGS; x++) {
- for (y = 0; y < VPGSEGS; y++) {
- lopenpg[pgn][x][y][0] = ropenpg[pgn][x][y][0] * -1.0;
- lopenpg[pgn][x][y][1] = ropenpg[pgn][x][y][1];
- lopenpg[pgn][x][y][2] = ropenpg[pgn][x][y][2];
- }
- }
- }
-
- /* offset the crack .01" for zbuffer */
- crackvtx[0][0] = ropenpg[0][0][0][0];
- crackvtx[0][1] = ropenpg[0][0][0][1];
- crackvtx[0][2] = ropenpg[0][0][0][2] + 0.0;
- crackvtx[1][0] = ropenpg[0][0][VPGSEGS - 1][0];
- crackvtx[1][1] = ropenpg[0][0][VPGSEGS - 1][1];
- crackvtx[1][2] = ropenpg[0][0][VPGSEGS - 1][2] + 0.0;
-
- /* make the array for the right cover */
- for (pgn = 0; pgn < OPENFRAMES; pgn++) {
- for (x = 0;x < COVERSEGS; x++) {
- ropencover[pgn][x][0][0] = opencover[pgn][x][0] * SCALE;
- ropencover[pgn][x][0][1] = -COVEROVERHANG;
- ropencover[pgn][x][0][2] = opencover[pgn][x][1] * SCALE;
- ropencover[pgn][x][1][0] = opencover[pgn][x][0] * SCALE;
- ropencover[pgn][x][1][1] = PGHT + COVEROVERHANG;
- ropencover[pgn][x][1][2] = opencover[pgn][x][1] * SCALE;
- }
- }
-
- /* make the array for the left cover */
- for (pgn = 0; pgn < OPENFRAMES; pgn++) {
- for (x = 0;x < COVERSEGS; x++) {
- for (y = 0; y < 2; y++) {
- lopencover[pgn][x][y][0] = ropencover[pgn][x][y][0] * -1.0;
- lopencover[pgn][x][y][1] = ropencover[pgn][x][y][1];
- lopencover[pgn][x][y][2] = ropencover[pgn][x][y][2];
- }
- }
- }
-
- /* make array for the binding */
- for (x = 0; x < BINDINGSEGS; x++) {
- sbinding[x][0][0] = binding[x][0] * SCALE;
- sbinding[x][0][1] = -COVEROVERHANG;
- sbinding[x][0][2] = binding[x][1] * SCALE;
- sbinding[x][1][0] = binding[x][0] * SCALE;
- sbinding[x][1][1] = PGHT + COVEROVERHANG;
- sbinding[x][1][2] = binding[x][1] * SCALE;
- }
-
- /* make array for the page next to the cover */
- mk_right_basepg();
-
- for (pgn = 0; pgn < OPENFRAMES; pgn++) {
- for (x = 0; x < 3; x++) {
- for(y = 0; y < 2; y++) {
- lopenbasepg[pgn][x][y][0] = ropenbasepg[pgn][x][y][0] * -1.0;
- lopenbasepg[pgn][x][y][1] = ropenbasepg[pgn][x][y][1];
- lopenbasepg[pgn][x][y][2] = ropenbasepg[pgn][x][y][2];
- }
- }
- }
-
- mksqrttable();
- }
-
-
- /* assume cover is 10" and we want 1/4" cover overlap */
- static void mk_right_basepg()
- {
- int pgn, x;
- float tenx, tenz;
-
- for (pgn = 0; pgn < OPENFRAMES; pgn++) {
- ropenbasepg[pgn][0][0][0] = 0.0;
- ropenbasepg[pgn][0][0][1] = 0.0;
-
- /* gap between pages and binding increases from 1/6"" to 0.25" */
- ropenbasepg[pgn][0][0][2] =
- -0.5 + ((float)(OPENFRAMES - 1 - pgn) / (OPENFRAMES -1) * 0.25);
- ropenbasepg[pgn][1][0][0] = ropencover[pgn][0][0][0];
- ropenbasepg[pgn][1][0][1] = 0.0;
- ropenbasepg[pgn][1][0][2] = ropencover[pgn][0][0][2];
- tenx = ropencover[pgn][COVERSEGS - 1][0][0] - ropencover[pgn][0][0][0];
- tenz = ropencover[pgn][COVERSEGS - 1][0][2] - ropencover[pgn][0][0][2];
- tenx = tenx / 43.0;
- tenz = tenz / 43.0;
- ropenbasepg[pgn][2][0][0] = ropencover[pgn][COVERSEGS-1][0][0] - tenx;
- ropenbasepg[pgn][2][0][1] = 0.0;
- ropenbasepg[pgn][2][0][2] = ropencover[pgn][COVERSEGS-1][0][2] - tenz;
- }
-
- for (pgn = 0; pgn < OPENFRAMES; pgn++) {
- for (x = 0; x < 3; x++) {
- ropenbasepg[pgn][x][1][0] = ropenbasepg[pgn][x][0][0];
- ropenbasepg[pgn][x][1][1] = PGHT;
- ropenbasepg[pgn][x][1][2] = ropenbasepg[pgn][x][0][2];
- }
- }
- }
-
-
-
- mksqrttable()
- {
- register int i;
-
- for (i = 0; i < 4000; i++) {
- sqrttable[i] = fsqrt((float)i);
- }
-
- }
-
-
- /* make additional arrays needed to turn pages */
- void mk_turn_arrays()
- {
- register int pgn, x, y;
-
- for (pgn = 0; pgn < TURNFRAMES; pgn++) {
- for(x = 0; x < PGSEGS; x++) {
- for(y = 0; y < VPGSEGS; y++) {
- rtolpglst[pgn][x][y][0] = turnpg[pgn][x][0] * SCALE;
- rtolpglst[pgn][x][y][1] = PGHT/(VPGSEGS - 1) * y;
- rtolpglst[pgn][x][y][2] = turnpg[pgn][x][1] * SCALE;
- }
- }
- }
- for (pgn = 0; pgn < TURNFRAMES; pgn++) {
- for(x = 0; x < PGSEGS; x++) {
- for(y = 0; y < VPGSEGS; y++) {
- ltorpglst[pgn][x][y][0] = rtolpglst[pgn][x][y][0] * -1.0;
- ltorpglst[pgn][x][y][1] = rtolpglst[pgn][x][y][1];
- ltorpglst[pgn][x][y][2] = rtolpglst[pgn][x][y][2];
- }
- }
- }
- mkangles();
- mknorms();
- }
-
-
- void mkangles(void)
- {
- register int x, maxx, frame;
-
- maxx = PGSEGS -1;
- for (frame = 0; frame < OPENFRAMES; frame++) {
- for (x = 0; x < maxx; x++) {
- ropenangle[frame][x] =
- getangle(ropenpg[frame][x][0],ropenpg[frame][x+1][0]);
-
- lopenangle[frame][x] =
- getangle(lopenpg[frame][x+1][0],lopenpg[frame][x][0]);
- }
- }
-
- for (frame = 0; frame < TURNFRAMES; frame++) {
- for (x = 0; x < maxx; x++) {
- frontrturnangle[frame][x] =
- getangle(rtolpglst[frame][x][0],rtolpglst[frame][x+1][0]);
- backrturnangle[frame][x] =
- getangle(rtolpglst[frame][x+1][0],rtolpglst[frame][x][0]);
-
- backlturnangle[frame][x] =
- getangle(ltorpglst[frame][x+1][0],ltorpglst[frame][x][0]);
- frontlturnangle[frame][x] =
- getangle(ltorpglst[frame][x][0],ltorpglst[frame][x+1][0]);
- }
- }
- }
-
-
- static float getangle(register float vtx1[3], register float vtx2[3])
- {
- register float dx, dz, angle;
-
- dx = vtx2[0] - vtx1[0];
- dz = vtx2[2] - vtx1[2];
-
- if (dz == 0 && dx ==0) {
- fprintf(stderr,"error in angle calculation\n");
- return(0);
- }
-
- angle = atan2f(-dz,dx);
- angle *= 360.0 / (2.0 * M_PI);
-
- return(angle);
- }
-
-
- void mknorms()
- {
- register int frame, x, y;
-
- for (frame = 0; frame < TURNFRAMES; frame++) {
- for (x = 0; x < PGSEGS -1; x++) {
- for (y = 0; y < VPGSEGS -1; y++) {
- normdot(rtolpglst[frame][x][y],rtolpglst[frame][x+1][y],
- rtolpglst[frame][x+1][y+1],rtolnorm[frame][x][y],
- COUNTER_CLOCKWISE);
-
- normdot(ltorpglst[frame][x+1][y],ltorpglst[frame][x][y],
- ltorpglst[frame][x][y+1],ltornorm[frame][x][y],
- COUNTER_CLOCKWISE);
-
-
- }
- }
- }
- }
-
-
- /* assume positive normal for COUNTER_CLOCKWISE position */
- normdot(v0, v1, v2, norm, direction)
- float v0[3], v1[3], v2[3], norm[3];
- int direction;
- {
- float x0, x1, y0, y1, z0, z1;
- float rad;
-
- x0 = v0[0] - v1[0];
- y0 = v0[1] - v1[1];
- z0 = v0[2] - v1[2];
-
- x1 = v2[0] - v1[0];
- y1 = v2[1] - v1[1];
- z1 = v2[2] - v1[2];
-
- norm[0] = y0 * z1 - z0 * y1;
- norm[1] = -(x0 * z1 - z0 * x1);
- norm[2] = x0 * y1 - y0 * x1;
-
- rad = sqrt (norm[0] * norm[0] + norm[1] * norm[1] + norm[2] * norm[2]);
- /* change these to positive for clockwise normal */
- norm[0] = (float)direction * norm[0]/rad;
- norm[1] = (float)direction * norm[1]/rad;
- norm[2] = (float)direction * norm[2]/rad;
- }
-
-
-
- /*******************************************************
- /* MOTION STUFF
- /******************************************************/
-
- /* this routine increments through the keyframes to draw the book opening.
- NOTE: it does not draw the last frame of the opened book - pgn = 0 */
- void openbook(register int rotateflag)
- {
- register int pgn;
-
- /* to draw the fully open book change pgn > 0 to pgn >= 0 */
- /* for (pgn = OPENFRAMES -1; pgn >= 0; pgn--) { /* draw fully open book */
- for (pgn = OPENFRAMES -1; pgn > 0; pgn--) { /* draw once */
-
- cpack(0);
- clear();
- /*
- zclear();
- */
-
- /* probably want to draw the background here */
-
- if (rotateflag) {
- rotate(ROTINC,'x');
- rotate(ROTINC,'y');
- }
-
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- drawopenframe(pgn);
- popmatrix();
-
- swapbuffers();
- /*
- if (pgn == OPENFRAMES -1)
- sginap(100);
- */
- }
- }
-
- /* This is the same as drawopenframe() except it does a clear before and a
- swapbuffers() after. Use this if you want to only draw the book open */
- drawopenbook(register int rotateflag)
- {
- cpack(0);
- clear();
-
- if (rotateflag) {
- zclear();
- }
-
- drawopenframe(0);
- swapbuffers();
- }
-
-
- #if DRAWSOLIDPAGES
- static void drawsolidpages()
- {
- int x, y;
- float carray[3];
-
- y = VPGSEGS - 1;
- bgnpolygon();
- for (x = 0; x < PGSEGS; x++) {
- mkcolor(carray,pgcolor,ropenpg[0][x][y]);
- c3f(carray);
- v3f(ropenpg[0][x][y]);
- }
- for (x = PGSEGS - 1; x >= 0; x--) {
- mkcolor(carray,pgcolor,ropenpg[0][x][0]);
- c3f(carray);
- v3f(ropenpg[0][x][0]);
- }
- endpolygon();
- bgnpolygon();
- for (x = 0; x < PGSEGS; x++) {
- mkcolor(carray,pgcolor,lopenpg[0][x][y]);
- c3f(carray);
- v3f(lopenpg[0][x][y]);
- }
- for (x = PGSEGS - 1; x >= 0; x--) {
- mkcolor(carray,pgcolor,lopenpg[0][x][0]);
- c3f(carray);
- v3f(lopenpg[0][x][0]);
- }
- endpolygon();
- }
- #endif
-
-
- void pickdrawopenframe(register int pgn)
- {
- pickdrawedges(ropenpg[pgn],lopenpg[pgn],ropenbasepg[pgn],lopenbasepg[pgn]);
- if (pgn != (OPENFRAMES - 1)) { /* don't draw pages when book is closed */
- if (leftpage != NULL && closeup <= 0)
- pickdrawicons(leftpage, BACK, lopenpg[pgn], lopenangle[pgn]);
- if (rightpage != NULL && closeup >= 0)
- pickdrawicons(rightpage, FRONT, ropenpg[pgn], ropenangle[pgn]);
- }
- }
-
- /* this routing draws a keyframe (frame #pgn) of the book opening */
- void drawopenframe(register int pgn)
- {
- float tmp;
-
- tmp = color_mult;
- color_mult = 1.0;
- drawopencover(ropencover[pgn],lopencover[pgn]);
- fillopenpages(ropenpg[pgn],lopenpg[pgn],ropenbasepg[pgn],lopenbasepg[pgn]);
-
- #if DRAWSOLIDPAGES
- if (pgn == 0 && !isdoublebuffer())
- drawsolidpages();
- #endif
-
- if (pgn != (OPENFRAMES - 1)) { /* don't draw pages when book is closed */
- drawopenpages(ropenpg[pgn],lopenpg[pgn]);
- if (leftpage != NULL && closeup <= 0)
- drawicons(leftpage, BACK, lopenpg[pgn], lopenangle[pgn]);
- if (rightpage != NULL && closeup >= 0)
- drawicons(rightpage, FRONT, ropenpg[pgn], ropenangle[pgn]);
- /*
- drawicons_dave(lopenpg[pgn],ropenpg[pgn],lopenangle[pgn],ropenangle[pgn]);
- */
- }
- if (!OPENBOOK)
- color_mult = tmp;
- }
-
-
- /* Draw the cover and the binding of the book. This routine can be sped up
- considerably by pre-calculating color arrays for the right and left cover
- and the binding */
- static void drawopencover(register float rcover[COVERSEGS][2][THREED],
- register float lcover[PGSEGS][2][THREED])
- {
- register float carray[3];
-
- /* draw the right cover */
- bgnpolygon();
- mkcolor(carray,covercolor,rcover[0][0]);
- c3f(carray);
- v3f(rcover[0][0]);
- mkcolor(carray,covercolor,rcover[1][0]);
- c3f(carray);
- v3f(rcover[1][0]);
- mkcolor(carray,covercolor,rcover[1][1]);
- c3f(carray);
- v3f(rcover[1][1]);
- mkcolor(carray,covercolor,rcover[0][1]);
- c3f(carray);
- v3f(rcover[0][1]);
- endpolygon();
-
- /* draw the left cover */
- bgnpolygon();
- mkcolor(carray,covercolor,lcover[0][0]);
- c3f(carray);
- v3f(lcover[0][0]);
- mkcolor(carray,covercolor,lcover[1][0]);
- c3f(carray);
- v3f(lcover[1][0]);
- mkcolor(carray,covercolor,lcover[1][1]);
- c3f(carray);
- v3f(lcover[1][1]);
- mkcolor(carray,covercolor,lcover[0][1]);
- c3f(carray);
- v3f(lcover[0][1]);
- endpolygon();
-
- drawbinding();
- }
-
- void darken(register float carray[3])
- {
- float rdiff, bdiff, gdiff;
-
- rdiff = carray[0] * .25;
- bdiff = carray[1] * .25;
- gdiff = carray[2] * .25;
-
- carray[0] = carray[0] - rdiff;
- carray[1] = carray[1] - bdiff;
- carray[2] = carray[2] - gdiff;
-
- if (carray[0] < 0.0)
- carray[0] = 0.0;
- if (carray[1] < 0.0)
- carray[1] = 0.0;
- if (carray[2] < 0.0)
- carray[2] = 0.0;
- }
-
- void lighten(register float carray[3])
- {
- float rdiff, bdiff, gdiff;
-
- rdiff = 1.0 - carray[0];
- bdiff = 1.0 - carray[1];
- gdiff = 1.0 - carray[2];
-
- carray[0] = carray[0] + rdiff * .25;
- carray[1] = carray[1] + bdiff * .25;
- carray[2] = carray[2] + gdiff * .25;
-
- if (carray[0] > 1.0)
- carray[0] = 1.0;
- if (carray[1] > 1.0)
- carray[1] = 1.0;
- if (carray[2] > 1.0)
- carray[2] = 1.0;
- }
-
- void outlinebinding()
- {
- bgnline();
- v3f(sbinding[0][0]);
- v3f(sbinding[0][1]);
- v3f(sbinding[BINDINGSEGS - 1][1]);
- v3f(sbinding[BINDINGSEGS - 1][0]);
- v3f(sbinding[0][0]);
- endline();
- }
-
- void drawbinding()
- {
- register int x;
- register float carray[3];
-
- /* draw the binding */
- for (x = 0; x < (BINDINGSEGS - 1); x++) {
- bgnpolygon();
- mkcolor(carray,covercolor,sbinding[x][0]);
- if (x == 2)
- lighten(carray);
- else if (x == 0)
- darken(carray);
- c3f(carray);
- v3f(sbinding[x][0]);
- mkcolor(carray,covercolor,sbinding[x+1][0]);
- if (x == 2)
- lighten(carray);
- else if (x == 0)
- darken(carray);
- c3f(carray);
- v3f(sbinding[x+1][0]);
- mkcolor(carray,covercolor,sbinding[x+1][1]);
- if (x == 2)
- lighten(carray);
- else if (x == 0)
- darken(carray);
- c3f(carray);
- v3f(sbinding[x+1][1]);
- mkcolor(carray,covercolor,sbinding[x][1]);
- if (x == 2)
- lighten(carray);
- else if (x == 0)
- darken(carray);
- c3f(carray);
- v3f(sbinding[x][1]);
- endpolygon();
- }
- }
-
- void outlineedge(register float pg[PGSEGS][VPGSEGS][THREED],
- register float base[3][2][THREED])
- {
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- bgnline();
- v3f(base[2][0]);
- v3f(base[2][1]);
- v3f(pg[PGSEGS -1][VPGSEGS - 1]);
- v3f(pg[PGSEGS -1][0]);
- v3f(base[2][0]);
- endline();
- popmatrix();
- }
-
- void outlineleftedge()
- {
- dooverlayview();
- color(PUP_COLOR);
- outlineedge( lopenpg[0],lopenbasepg[0]);
- dobookview();
- }
-
- void outlinerightedge()
- {
- dooverlayview();
- color(PUP_COLOR);
- outlineedge( ropenpg[0],ropenbasepg[0]);
- dobookview();
- }
-
- void pickdrawedges(register float ropg[PGSEGS][VPGSEGS][THREED],
- register float lopg[PGSEGS][VPGSEGS][THREED],
- register float robase[3][2][THREED], register float lobase[3][2][THREED])
- {
- /* leftside */
- if (leftpage != NULL)
- {
- loadname(80);
- bgnpolygon();
- v3f(lobase[2][0]);
- v3f(lobase[2][1]);
- v3f(lopg[PGSEGS -1][VPGSEGS - 1]);
- v3f(lopg[PGSEGS -1][0]);
- endpolygon();
- }
- /* rightside */
- if (rightpage != NULL)
- {
- loadname(81);
- bgnpolygon();
- v3f(robase[2][0]);
- v3f(robase[2][1]);
- v3f(ropg[PGSEGS -1][VPGSEGS - 1]);
- v3f(ropg[PGSEGS -1][0]);
- endpolygon();
- }
- }
-
- /* This routine draws the page edges between the cover and the inside right and
- left pages of the opening book. The openbasepage is the page flattened out
- on the cover. This routine can be sped up considerably by pre-calculating
- color arrays for the right and left page edges and the right and left
- basepages. */
- static void fillopenpages(register float ropg[PGSEGS][VPGSEGS][THREED],
- register float lopg[PGSEGS][VPGSEGS][THREED],
- register float robase[3][2][THREED], register float lobase[3][2][THREED])
- {
- register int x;
- register float carray[3];
-
- /* draw the back right page edges */
- bgnpolygon();
-
- /* trace along the page edge */
- for (x = 0; x < PGSEGS; x++) {
- mkcolor(carray,pgedgecolor,ropg[x][VPGSEGS - 1]);
- c3f(carray);
- v3f(ropg[x][VPGSEGS - 1]);
- }
-
- /* trace along the basepage */
- mkcolor(carray,pgedgecolor,robase[2][1]);
- c3f(carray);
- v3f(robase[2][1]);
- mkcolor(carray,pgedgecolor,robase[1][1]);
- c3f(carray);
- v3f(robase[1][1]);
- mkcolor(carray,pgedgecolor,robase[0][1]);
- c3f(carray);
- v3f(robase[0][1]);
- endpolygon();
-
- /* draw the right side page edges */
- bgnpolygon();
- mkcolor(carray,pgedgecolor,robase[2][0]);
- c3f(carray);
- v3f(robase[2][0]);
- mkcolor(carray,pgedgecolor,robase[2][1]);
- c3f(carray);
- v3f(robase[2][1]);
- mkcolor(carray,pgedgecolor,ropg[PGSEGS -1][VPGSEGS - 1]);
- c3f(carray);
- v3f(ropg[PGSEGS -1][VPGSEGS - 1]);
- mkcolor(carray,pgedgecolor,ropg[PGSEGS -1][0]);
- c3f(carray);
- v3f(ropg[PGSEGS -1][0]);
- endpolygon();
-
- /* draw the left side of the right pages (above the binding) ??? */
-
- /* fraw the right front page edges */
- bgnpolygon();
-
- /* trace along the page edge */
- for (x = 0; x < PGSEGS; x++) {
- mkcolor(carray,pgedgecolor,ropg[x][0]);
- c3f(carray);
- v3f(ropg[x][0]);
- }
-
- /* trace along the basepage */
- mkcolor(carray,pgedgecolor,robase[2][0]);
- c3f(carray);
- v3f(robase[2][0]);
- mkcolor(carray,pgedgecolor,robase[1][0]);
- c3f(carray);
- v3f(robase[1][0]);
- mkcolor(carray,pgedgecolor,robase[0][0]);
- c3f(carray);
- v3f(robase[0][0]);
- endpolygon();
-
- /* draw the back left page edges */
- bgnpolygon();
-
- /* trace along the page edge */
- for (x = 0; x < PGSEGS; x++) {
- mkcolor(carray,pgedgecolor,lopg[x][VPGSEGS - 1]);
- c3f(carray);
- v3f(lopg[x][VPGSEGS - 1]);
- }
-
- /* trace along the basepage */
- mkcolor(carray,pgedgecolor,lobase[2][1]);
- c3f(carray);
- v3f(lobase[2][1]);
- mkcolor(carray,pgedgecolor,lobase[1][1]);
- c3f(carray);
- v3f(lobase[1][1]);
- mkcolor(carray,pgedgecolor,lobase[0][1]);
- c3f(carray);
- v3f(lobase[0][1]);
- endpolygon();
-
- /* draw the left side page edges */
- bgnpolygon();
- mkcolor(carray,pgedgecolor,lobase[2][0]);
- c3f(carray);
- v3f(lobase[2][0]);
- mkcolor(carray,pgedgecolor,lobase[2][1]);
- c3f(carray);
- v3f(lobase[2][1]);
- mkcolor(carray,pgedgecolor,lopg[PGSEGS -1][VPGSEGS - 1]);
- c3f(carray);
- v3f(lopg[PGSEGS -1][VPGSEGS - 1]);
- mkcolor(carray,pgedgecolor,lopg[PGSEGS -1][0]);
- c3f(carray);
- v3f(lopg[PGSEGS -1][0]);
- endpolygon();
-
- /* Could draw the right side of the left pages (above the binding), but I
- don't think we really need this */
-
- /* fraw the left front page edges */
- bgnpolygon();
-
- /* trace along the page edge */
- for (x = 0; x < PGSEGS; x++) {
- mkcolor(carray,pgedgecolor,lopg[x][0]);
- c3f(carray);
- v3f(lopg[x][0]);
- }
-
- /* trace along the basepage */
- mkcolor(carray,pgedgecolor,lobase[2][0]);
- c3f(carray);
- v3f(lobase[2][0]);
- mkcolor(carray,pgedgecolor,lobase[1][0]);
- c3f(carray);
- v3f(lobase[1][0]);
- mkcolor(carray,pgedgecolor,lobase[0][0]);
- c3f(carray);
- v3f(lobase[0][0]);
- endpolygon();
- }
-
- void findleftpagesquare(int *x_ndx, int *y_ndx)
- {
- register int x,y;
- register int maxsq = PGSEGS - 1;
- register int maxvsq = VPGSEGS - 1;
- int name;
- short picbuf[PICBUFSIZ];
- int hits, i, j, c, num;
- int picked;
-
- dobookview();
- name = 0;
- picked = -1;
- pick(picbuf, PICBUFSIZ);
- dobookview();
- initnames();
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- /* draw the sections that make up the left page */
- for (x = 0; x < maxsq; x++) {
- for (y = 0; y < maxvsq; y++) {
- loadname(name);
- /* will never have to draw icon on 2 sides with this routine */
- drawsquare(lopenpg[0],x,y);
- name++;
- }
- }
- popmatrix();
- hits = endpick(picbuf);
- picked = get_picked(picbuf, hits);
- dobookview();
- if (picked >= 0 && picked < 100)
- {
- *x_ndx = picked / (maxsq-1);
- *y_ndx = picked - (*x_ndx*(maxsq-1));
- }
- else
- {
- *x_ndx = -1;
- *y_ndx = -1;
- }
- }
-
- void findrightpagesquare( int *x_ndx, int *y_ndx)
- {
- register int x,y;
- register int maxsq = PGSEGS - 1;
- register int maxvsq = VPGSEGS - 1;
- int name;
- short picbuf[PICBUFSIZ];
- int hits, i, j, c, num;
- int picked;
-
- name = 0;
- dobookview();
- picked = -1;
- pick(picbuf, PICBUFSIZ);
- dobookview();
- initnames();
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- /* draw the sections that make up the left page */
- for (x = 0; x < maxsq; x++) {
- for (y = 0; y < maxvsq; y++) {
- loadname(name);
- /* will never have to draw icon on 2 sides with this routine */
- drawsquare(ropenpg[0],x,y);
- name++;
- }
- }
- popmatrix();
- hits = endpick(picbuf);
- picked = get_picked(picbuf, hits);
- dobookview();
- if (picked >= 0 && picked < 100)
- {
- *x_ndx = picked / (maxsq-1);
- *y_ndx = picked - (*x_ndx*(maxsq-1));
- }
- else
- {
- *x_ndx = -1;
- *y_ndx = -1;
- }
- }
-
-
- /* draw the left and right opening pages. This routine could be speeded up
- considerably by pre-calculating color arrays for the left and right page
- vertices */
-
- static void drawopenpages(register float rpg[PGSEGS][VPGSEGS][THREED],
- register float lpg[PGSEGS][VPGSEGS][THREED])
- {
- register int x,y;
- register int maxsq = PGSEGS - 1;
- register int maxvsq = VPGSEGS - 1;
-
- /* draw the sections that make up the right page */
- for (x = 0; x < maxsq; x++) {
- for (y = 0; y < maxvsq; y++) {
- /* will never have to draw icon on 2 sides with this routine */
- drawsquare(rpg,x,y);
- }
- }
-
- /* draw the sections that make up the left page */
- for (x = 0; x < maxsq; x++) {
- for (y = 0; y < maxvsq; y++) {
- /* will never have to draw icon on 2 sides with this routine */
- drawsquare(lpg,x,y);
- }
- }
-
- drawcrack();
- }
-
- void turnpage(int side)
- {
- dobookview();
- mkdoublebuffer();
- pushmatrix();
- rot(-25.0, 'x');
- translate(0.0, 1.0, 0.0);
- if (side == 0) /* left */
- {
- middlepage = leftpage;
- leftpage = leftpage->prevpage;
- ltor_turn();
- rightpage = middlepage;
- }
- else if (side == 1) /* right */
- {
- middlepage = rightpage;
- rightpage = rightpage->nextpage;
- rtol_turn();
- leftpage = middlepage;
- }
- middlepage = NULL;
- mksinglebuffer();
- c3s(morecolors[10]);
- clear();
- drawopenframe(0);
- popmatrix();
- swapbuffers();
- }
-
- void rtol_turn()
- {
- register int frame, x, y;
- register int maxframe = TURNFRAMES -1;
- register int maxx = PGSEGS - 1;
- register int maxy = VPGSEGS - 1;
- float carray[3];
- struct icntmpltstruct * fronticon[PGSEGS-1][VPGSEGS-1];
- struct icntmpltstruct * backicon[PGSEGS-1][VPGSEGS-1];
- struct iconstruct *tmpicon;
- float transname;
- int count;
-
- for (x = 0; x < maxx; x++)
- {
- for (y = 0; y < maxy; y++)
- {
- fronticon[x][y] = NULL;
- backicon[x][y] = NULL;
- }
- }
- tmpicon = middlepage->fronticons;
- count = 0;
- while (tmpicon != NULL && count < ICONLIMIT)
- {
- if (!Hide || tmpicon->ok)
- {
- fronticon[tmpicon->xposition_ndx][tmpicon->yposition_ndx] = tmpicon->iconptr;
- count++;
- }
- tmpicon = tmpicon->nexticon;
- }
- tmpicon = middlepage->backicons;
- count = 0;
- while (tmpicon != NULL && count < ICONLIMIT)
- {
- if (!Hide || tmpicon->ok)
- {
- backicon[tmpicon->xposition_ndx][tmpicon->yposition_ndx] = tmpicon->iconptr;
- count++;
- }
- tmpicon = tmpicon->nexticon;
- }
- for (frame = 1; frame < maxframe; frame++) {
- cpack(0);
- clear();
- zclear();
-
- drawopenframe(0);
-
- /* draw the turning page */
- for (x = 0; x < maxx; x++) {
- for (y = 0; y < maxy; y++) {
- transname = -.15;
- drawsquare(rtolpglst[frame],x,y);
- if (rtolnorm[frame][x][y][2] > 0) { /* if front pointing up */
- if (fronticon[x][y] != NULL)
- {
- pushmatrix();
- translate( rtolpglst[frame][x][y][0],
- rtolpglst[frame][x][y][1]+.4, rtolpglst[frame][x][y][2]);
- rotate( (int)(frontrturnangle[frame][x] * 10 + 0.5), 'y');
- if (fronticon[x][y]->poly != NULL)
- drawicon_geom(0, fronticon[x][y]);
- else if (fronticon[x][y]->tex_image != NULL)
- drawicon_img(0,fronticon[x][y]);
- else
- transname = 1.125;
- pushmatrix();
- translate(0.0, transname, 0.0);
- draw_demoname(fronticon[x][y]);
- popmatrix();
- popmatrix();
- }
- } else {/* front must point down */
- if (backicon[x][y] != NULL)
- {
- pushmatrix();
- translate( rtolpglst[frame][x+1][y][0],
- rtolpglst[frame][x+1][y][1]+.4, rtolpglst[frame][x+1][y][2]);
- rotate( (int)(backrturnangle[frame][x] * 10 + 0.5), 'y');
- if (backicon[x][y]->poly != NULL)
- drawicon_geom(0, backicon[x][y]);
- else if (backicon[x][y]->tex_image != NULL)
- drawicon_img(0,backicon[x][y]);
- else
- transname = 1.125;
- pushmatrix();
- translate(0.0, transname, 0.0);
- draw_demoname(backicon[x][y]);
- popmatrix();
- popmatrix();
- }
- }
- }
- if (x == 0)
- drawcrack();
- }
-
- /* outline the page */
- bgnline();
- for (x = 0; x < PGSEGS; x++) {
- mkcolor(carray,pgedgecolor,rtolpglst[frame][x][0]);
- c3f(carray);
- v3f(rtolpglst[frame][x][0]);
- }
- mkcolor(carray,pgedgecolor,rtolpglst[frame][PGSEGS-1][VPGSEGS-1]);
- c3f(carray);
- v3f(rtolpglst[frame][PGSEGS-1][VPGSEGS-1]);
- endline();
- swapbuffers();
- }
- }
-
-
- void ltor_turn()
- {
- register int frame, x, y;
- register int maxframe = TURNFRAMES -1;
- register int maxx = PGSEGS - 1;
- register int maxy = VPGSEGS - 1;
- float carray[3];
- struct icntmpltstruct * fronticon[PGSEGS-1][VPGSEGS-1];
- struct icntmpltstruct * backicon[PGSEGS-1][VPGSEGS-1];
- struct iconstruct *tmpicon;
- float transname;
- int count;
-
- for (x = 0; x < maxx; x++)
- {
- for (y = 0; y < maxy; y++)
- {
- fronticon[x][y] = NULL;
- backicon[x][y] = NULL;
- }
- }
- tmpicon = middlepage->fronticons;
- count = 0;
- while (tmpicon != NULL && count < ICONLIMIT)
- {
- if (!Hide || tmpicon->ok)
- {
- fronticon[tmpicon->xposition_ndx][tmpicon->yposition_ndx] = tmpicon->iconptr;
- count++;
- }
- tmpicon = tmpicon->nexticon;
- }
- tmpicon = middlepage->backicons;
- count = 0;
- while (tmpicon != NULL && count < ICONLIMIT)
- {
- if (!Hide || tmpicon->ok)
- {
- backicon[tmpicon->xposition_ndx][tmpicon->yposition_ndx] = tmpicon->iconptr;
- count++;
- }
- tmpicon = tmpicon->nexticon;
- }
-
- for (frame = 1; frame < maxframe; frame++) {
- cpack(0);
- clear();
- zclear();
-
- drawopenframe(0);
-
- /* draw the turning page */
- for (x = 0; x < maxx; x++) {
- for (y = 0; y < maxy; y++) {
- transname = -.15;
- drawsquare(ltorpglst[frame],x,y);
- if (ltornorm[frame][x][y][2] > 0) { /* if back pointing up */
- if (backicon[x][y] != NULL)
- {
- pushmatrix();
- translate( ltorpglst[frame][x+1][y][0],
- ltorpglst[frame][x+1][y][1]+.4, ltorpglst[frame][x+1][y][2]);
- rotate((int)(backlturnangle[frame][x] * 10 + 0.5), 'y');
- if (backicon[x][y]->poly != NULL)
- drawicon_geom(0, backicon[x][y]);
- else if (backicon[x][y]->tex_image != NULL)
- drawicon_img(0,backicon[x][y]);
- else
- transname = 1.125;
- pushmatrix();
- translate(0.0, transname, 0.0);
- draw_demoname(backicon[x][y]);
- popmatrix();
- popmatrix();
- }
- } else {/* front must point up */
- if (fronticon[x][y] != NULL)
- {
- pushmatrix();
- translate( ltorpglst[frame][x][y][0],
- ltorpglst[frame][x][y][1]+.4, ltorpglst[frame][x][y][2]);
- rotate( (int)(frontlturnangle[frame][x] * 10 + 0.5), 'y');
- if (fronticon[x][y]->poly != NULL)
- drawicon_geom(0, fronticon[x][y]);
- else if (fronticon[x][y]->tex_image != NULL)
- drawicon_img(0,fronticon[x][y]);
- else
- transname = 1.125;
- pushmatrix();
- translate(0.0, transname, 0.0);
- draw_demoname(fronticon[x][y]);
- popmatrix();
- popmatrix();
- }
- }
- }
- if (x == 0)
- drawcrack();
- }
-
- bgnline();
- for (x = 0; x < PGSEGS; x++) {
- mkcolor(carray,pgedgecolor,ltorpglst[frame][x][0]);
- c3f(carray);
- v3f(ltorpglst[frame][x][0]);
- }
- mkcolor(carray,pgedgecolor,ltorpglst[frame][PGSEGS-1][VPGSEGS-1]);
- c3f(carray);
- v3f(ltorpglst[frame][PGSEGS-1][VPGSEGS-1]);
- endline();
-
- swapbuffers();
- }
- }
-
- /* outline a square section of the page (5x5 squares) */
- static void drawoutlinesquare(register float pgarray[PGSEGS][VPGSEGS][THREED],
- register int x, register int y)
- {
- float center[3];
-
- center[0] = ( pgarray[x][y][0] + pgarray[x+1][y][0] +
- pgarray[x+1][y+1][0] + pgarray[x][y+1][0] ) / 4;
- center[1] = ( pgarray[x][y][1] + pgarray[x+1][y][1] +
- pgarray[x+1][y+1][1] + pgarray[x][y+1][1] ) / 4;
- center[2] = ( pgarray[x][y][2] + pgarray[x+1][y][2] +
- pgarray[x+1][y+1][2] + pgarray[x][y+1][2] ) / 4;
- pushmatrix();
- translate(center[0], center[1], center[2]);
- scale(.9, .9, 1.0);
- translate(-center[0], -center[1], -center[2]);
- bgnline();
- v3f(pgarray[x][y]);
- v3f(pgarray[x+1][y]);
- v3f(pgarray[x+1][y+1]);
- v3f(pgarray[x][y+1]);
- v3f(pgarray[x][y]);
- endline();
- popmatrix();
- }
-
- /* draw a square section of the page (5x5 squares) */
- static void drawsquare(register float pgarray[PGSEGS][VPGSEGS][THREED],
- register int x, register int y)
- {
- register float carray[3];
-
- bgnpolygon();
- mkcolor(carray,pgcolor,pgarray[x][y]);
- c3f(carray);
- v3f(pgarray[x][y]);
- mkcolor(carray,pgcolor,pgarray[x+1][y]);
- c3f(carray);
- v3f(pgarray[x+1][y]);
- mkcolor(carray,pgcolor,pgarray[x+1][y+1]);
- c3f(carray);
- v3f(pgarray[x+1][y+1]);
- mkcolor(carray,pgcolor,pgarray[x][y+1]);
- c3f(carray);
- v3f(pgarray[x][y+1]);
- endpolygon();
-
- /* this is where we can draw the icon for the square section. There needs
- to be a flag to determine if we need to draw bothe sides or not */
- }
-
-
-
- /*******************************************************
- /* COLOR STUFF
- /******************************************************/
-
- void setcovercolor(struct grptmpltstruct *grpptr)
- {
-
- covercolor[0] = grpptr->covercolor[0];
- covercolor[1] = grpptr->covercolor[1];
- covercolor[2] = grpptr->covercolor[2];
- }
-
-
- /* simple color calculation based on distance of light only - Note: 1/14/92
- this routine called 3496 times to open the book, and 4776 times to turn a
- page */
- static void mkcolor(register float carray[3], register float srcarray[3],
- register float coord[THREED])
- {
- register float distance;
- register float dx, dy, dz;
- static float lightplace[THREED] = {-10,-10,10};
- #if LIGHTCALC
- static float mindist = 1000.0;
- static float maxdist = 0.0;
- #endif
-
- dx = lightplace[0] - coord[0];
- dy = lightplace[1] - coord[1];
- dz = lightplace[2] - coord[2];
-
- /* distance - fsqrt(dx*dx + dy*dy + dz*dz); */
- distance = sqrttable[(int)(dx*dx + dy*dy + dz*dz)];
-
- #if LIGHTCALC
- if (mindist > distance) {
- mindist = distance;
- printf("mindist=%f\n",mindist);
- }
- if (maxdist < distance) {
- maxdist = distance;
- printf("maxdist=%f\n",maxdist);
- }
- #endif
-
- #if LIGHTCALC
- carray[0] = carray[1] = carray[2] =
- 1.0 - ((distance - mindist) / (maxdist - mindist));
- #else
- /* mindist = 10.34 , maxdist = 31.17 when lightplace = -10,-10,10 */
- /* mindist = 0.6 , maxdist = 18.4 when lightplace = 0,0,10 */
- /* mindist = 5.0 , maxdist = 22.9 when lightplace = -5,-5,10 */
- carray[0] = carray[1] = carray[2] = 1.0 - ((distance - 10.34) / 31.17);
- #endif
-
- carray[0] *= srcarray[0] * color_mult;
- carray[1] *= srcarray[1] * color_mult;
- carray[2] *= srcarray[2] * color_mult;
-
- #if LIGHTCALC
- /* printcolor(carray); */
- #endif
- }
-
- #if LIGHTCALC
- static void printcolor(float carray[3])
- {
- printf("%f,%f,%f \n",carray[0],carray[1],carray[2]);
- }
- #endif
-
-
- /* draw the crack between the right and left pages */
- static void drawcrack()
- {
- c3f(crackcolor);
- bgnline();
- v3f(crackvtx[0]);
- v3f(crackvtx[1]);
- endline();
- }
-
-
-
-
-
-
-
-